const experss = require("express")
const {
    asyncHandler
} = require("../getSendResult")
const router = experss.Router()

const {getDormitory,floor,roomNo,bednumber,getEvaluate,getMainRecords} = require("../../services/CurrServ")

/**
 *  查询宿舍楼
 */
router.get("/getDormitory",asyncHandler(async (req,res)=>{
    
    const reslut = await getDormitory(+req.query.id || null,+req.query.classId || null)
    
    return reslut
}))

/**
 * 查询楼层
 */
router.get("/floor",asyncHandler(async (req,res) => {
    const reslut = await floor({
        dormitoryId:+req.query.dormitoryId || null,
        floorId: +req.query.floorId || 0,
        classId: +req.query.classId || null
    })
    return reslut
}))

/**
 * 查询宿舍房间号
 */
router.get("/roomNo",asyncHandler(async (req,res)=>{
    const reslut = await roomNo({dormitoryId:+req.query.dormitoryId || null,floorId:+req.query.floorId || 0,roomNoId:+req.query.roomNoId || 0,classId: +req.query.classId || null})
    return reslut
}))
/**
 * 查询床位号
 */
router.get("/bednumber",asyncHandler(async (req,res) =>{
    const reslut = await bednumber({roomNoId:+req.query.roomNoId,bednumberId:+req.query.bednumberId || 0})
    return reslut
}))


/**
 * 获取宿舍评论
 */
router.get("/getEvaluate",asyncHandler(async(req,res) => {
    const reslut = await getEvaluate(+req.query.page || 1,+req.query.limit || 10,+req.query.roomNoId || null)
    return reslut
}))

/**
 * 获取维修记录
 */
router.get("/getMainRecords",asyncHandler(async(req,res) => {
    const reslut = await getMainRecords({
        page: +req.query.page || 1,
        limit: +req.query.limit || 10,
        startTime: req.query.startTime,
        endTime: req.query.endTime,
        dormitroyId: req.query.dormitroyId.map(item => {
            return +item
        }),
        floorId: +req.query.floorId || null,
        roomId: +req.query.roomId || null,
        isHandle: +req.query.isHandle
    })
    return reslut
}))





module.exports = router